package com.example.ecs.systems;

import com.example.ecs.components.PositionComponent;
import com.example.ecs.components.VelocityComponent;
import com.example.ecs.core.Entity;
import com.example.ecs.core.System;
/**
 * MovementSystem类负责更新所有具有位置和速度组件的实体的位置
 */
public class MovementSystem extends System {
    @Override
    public void update(double deltaTime) {
        for (Entity entity : entities) {
            if (entity.hasComponent(PositionComponent.class) && entity.hasComponent(VelocityComponent.class)) {
                PositionComponent position = entity.getComponent(PositionComponent.class);
                VelocityComponent velocity = entity.getComponent(VelocityComponent.class);
                
                position.x += velocity.vx * deltaTime;
                position.y += velocity.vy * deltaTime;
            }
        }
    }
}